package threading;

/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: WHY
 * Date: 2022-09-20
 * Time: 14:47
 */
class MyBlockingQueue {
    private int[] items = new int[1000];
    public int head = 0;
    public int tail = 0;
    public int size = 0;

    public void put(int elem) {//入队

        if (size >= items.length) {//判断是否满
            return;
        }
        items[tail] = elem;
        tail++;
        if (tail > items.length) {
            tail = 0;
        }
        size++;
    }
//出队列，返回删除的元素内容
    public Integer take() {
        if (size == 0) {
            return null;
        }
        //进行取元素操作
        int ret = items[head];
        head++;
        if (head > items.length) {
            head=0;
        }
        size--;
        return ret;
    }

}

public class Demo2 {

}
